package com.ceshiren.test.houduankaifa.controller;

import com.ceshiren.test.houduankaifa.dto.UserDto;
import com.ceshiren.test.houduankaifa.exception.ServiceException;
import com.ceshiren.test.houduankaifa.service.UserService;
import com.ceshiren.test.houduankaifa.util.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.rmi.server.ServerCloneException;

@Api(tags = "UserController: UserController用户登录post请求类")
@RestController
public class UserController {

    @Autowired
    UserService userService;


    @PostMapping(value = "/addUser",produces = "application/json")
    public Result addUser(@RequestBody UserDto user) {
        return userService.addUser(user);
    }

    @PostMapping(value = "/testException",produces = "application/json")
    public Result testException(@RequestBody UserDto user){
        if(user.getUsername()=="ceshiren"){
            int o = 100/0;
            return Result.success();
        }else {
            throw new ServiceException("123");
        }
    }

}
